package forums.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */
public class Forum {
	
	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(Forum.class);
	
	private Long id;
	private String name;
	private List<Message> messages;
	
	public Forum(Long id, String name) {
		this.id = id;
		this.name = name;
		this.messages = new ArrayList<Message>();
	}
	
	public Long getId() {
		return id;
	}
	
	public String getName() {
		return name;
	}
	
	public List<Message> getMessages() {
		return messages;
	}
	
	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}
	
	public void clearMessages() {
		messages.clear();
	}
	
	public Date getLastMessageDate() {
		// FIXME This isn't atomic, but should be to avoid possible
		// IndexOutOfBoundsException. Probably OK to just punt since it would
		// only happen when messages are deleted.
		return messages.get(messages.size() - 1).getDate();
	}
}
